#ifndef SYNC_UTILS_H_
#define SYNC_UTILS_H_
#include "defs.h"


class Mutex{
	friend class Condition;
private:
	pthread_mutex_t _mutex;
public:
	Mutex();
	~Mutex();
	void lock();
	void unlock();
};

class Condition {
private:
	pthread_cond_t _cond;
public:
	Condition();
	~Condition();
	void wait(Mutex& m);
	void signal(Mutex& m);
};

class Semaphore {
private:
	sem_t _sem;
public:
	Semaphore();
	~Semaphore();
	int get_value();
	int P(long tv = 0);
	void V();
};
class SpinLock {
private:
	pthread_spinlock_t _spinlock;

public:
	SpinLock();
	~SpinLock();
	void lock();
	void unlock();
};
#endif
